<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>股票实时刷新系统</title>
		<meta name="keywords" content="股票,实时,刷新,系统">
		<meta name="description" content="股票实时刷新系统">
		<%@ include file="public/head.jspf"%>
	</head>
	<body>
		<div class="box">
			<h1>股票实时刷新系统<a class="back">返回</a></h1>
			<div class="content">
				<div id="data">
					<table id="datalist">
						<caption>股票列表（<a href="javascript:refresh();">手动刷新</a>）</caption>
						<tr>
			                <th>ID</th>
			                <th>名称</th>
			                <th>价格</th>
			            </tr>
			            <tbody id="tb">
			            </tbody>
					</table>
				</div>
			</div>
		</div>
		<script type="text/javascript">
			$(function() {
			    setInterval(refresh, 5000); // 每5秒执行一次刷新
			});
			function refresh() {
					$.ajax({
					    type : "post",
					    dataType : "json",
					    url : "stock",
					    success : function(data) {
							$("#tb").empty();
							for (var i = 0; i < data.length; i++) {
							    var s = data[i];
							    $("#tb").append(
								    '<tr><td>' + s.id
								    + '</td><td>' + s.name
									+ '</td><td>' + s.price
									+ '</td></tr>');
							}
							tableInit();
					    }
					});
			    }
	    </script>
	</body>
</html>